package com.ht.base.system.biz.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.base.system.common.pojo.qto.SysDeptQTO;
import com.ht.base.system.dao.dao.SysDeptDao;
import com.ht.base.system.dao.domain.SysDeptDO;
import org.base.common.constans.SystemConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Set;

;

@Component
public class SysDeptMapper extends ServiceImpl<SysDeptDao, SysDeptDO> {
    @Resource
    private SysDeptDao sysDeptDao;

    public int insertDept(SysDeptDO deptDO) {
        deptDO.setStatus(SystemConstant.STR_0);
        deptDO.setCreateTime(new Date());
        deptDO.setUpdateTime(new Date());
        deptDO.setDelFlag(SystemConstant.STR_0);
        return sysDeptDao.insert(deptDO);
    }

    public List<SysDeptDO> findDeptByIds(Set<Long> idList) {
        return sysDeptDao.selectBatchIds(idList);
    }

    public Integer countByName(SysDeptDO deptDO) {
        LambdaQueryWrapper<SysDeptDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(deptDO.getParentId() != null, SysDeptDO::getParentId, deptDO.getParentId());
        wrapper.eq(StringUtils.isNotBlank(deptDO.getDeptName()), SysDeptDO::getDeptName, deptDO.getDeptName());

        Integer count = sysDeptDao.selectCount(wrapper);
        if (count == null) {
            count = 0;
        }
        return count;
    }

    public SysDeptDO findByDeptId(Long sysDeptId) {
        return sysDeptDao.findById(sysDeptId);
    }

    public List<SysDeptDO> findByCondition(SysDeptDO record) {
        return sysDeptDao.findByCondition(record);
    }

    public Integer findForPageCount(SysDeptQTO qto) {
        return sysDeptDao.findForPageCount(qto);
    }

    public List<SysDeptDO> findForPage(SysDeptQTO qto) {
        return sysDeptDao.findForPage(qto);
    }


}
